package cn.wsalix.observable.service.impl;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import cn.anlaser.form.UploadFileForm;
import cn.wsalix.admin.service.UserService;
import cn.wsalix.biz.service.AdvertiseService;
import cn.wsalix.biz.service.ArticleService;
import cn.wsalix.biz.service.CategoryService;
import cn.wsalix.biz.service.ImageFileService;
import cn.wsalix.biz.service.UploadFileService;
import cn.wsalix.observable.service.FileUploadService;
import cn.wsalix.shop.service.ProductService;
import cn.wsalix.shop.service.ShopService;
import cn.wsalix.user.service.UserInfoService;

public class FileUploadServiceImpl extends Observable implements
		FileUploadService {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	/*
	 * @Autowired private UserService userService;
	 * 
	 * @Autowired private CategoryService categoryService;
	 * 
	 * @Autowired private ShopService shopService;
	 * 
	 * @Autowired private ProductService productService;
	 * 
	 * @Autowired private UserInfoService userInfoService;
	 * 
	 * @Autowired private ArticleService articleService;
	 * 
	 * @Autowired private AdvertiseService advertiseService;
	 * 
	 * @Autowired private UploadFileService uploadFileService;
	 * 
	 * @Autowired private ImageFileService imageFileService;
	 */
	private List<? extends Observer> serviceList;
	private Object obj;

	@PostConstruct
	public void init() {
		for (Observer obj : serviceList) {
			addObserver(obj);
		}
		logger.info("==========init");

	}

	@PreDestroy
	public void destroy() {
		logger.info("==========destroy");
	}

	/*
	 * @Transactional
	 * 
	 * @Override public void upload(UploadFile entity) { setChanged();
	 * notifyObservers(entity); }
	 */
	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public List<? extends Observer> getServiceList() {
		return serviceList;
	}

	public void setServiceList(List<? extends Observer> serviceList) {
		this.serviceList = serviceList;
	}

	@Transactional
	@Override
	public void upload(UploadFileForm form) {
		setChanged();
		notifyObservers(form);
	}

}
